package com.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

/**
 * jdbc 入门
 */
public class Jdbc {
    public static void main(String[] args) throws Exception {
        // 1 . 注册驱动
        //Class.forName("com.mysql.jdbc.Driver");


        // 2. 获取连接
        String url = "jdbc:mysql://127.0.0.1:3306/bd1?useSSL=false";
        String username = "root";
        String password = "1234";
        Connection connection = DriverManager.getConnection(url, username, password);

        //3. 定义sql
        String sql = "update stu set age = 50 where id = 1";

        //4. 获取执行sql的对象Statement
        Statement statement = connection.createStatement();

        //5. 执行sql
        int n  = statement.executeUpdate(sql);

        //6. 处理结果
        System.out.println(n);

        //7 .释放资源
        statement.close();
        connection.close();

    }
}
